using System;
using System.Security.Cryptography;
using System.Text;
using Catastrophe.Common.FileM;

namespace Catastrophe.Common.EndeCrypt
{
	public class RsaCal : IEncrypt
	{
		public string KeyContainnerName { get; set; } = "DefaultContainner";


		public string BaseEncode(EncodeTypeEnum codeType, string value)
		{
			CspParameters parameters = new CspParameters
			{
				KeyContainerName = this.KeyContainnerName
			};
			using RSACryptoServiceProvider rSACryptoServiceProvider = new RSACryptoServiceProvider(parameters);
			byte[] bytes = Encoding.GetEncoding(GetEncodeTypeActual.GetValue(codeType)).GetBytes(value);
			byte[] inArray = rSACryptoServiceProvider.Encrypt(bytes, fOAEP: false);
			return Convert.ToBase64String(inArray);
		}

		public string BaseDecode(EncodeTypeEnum codeType, string value)
		{
			CspParameters parameters = new CspParameters
			{
				KeyContainerName = this.KeyContainnerName
			};
			using RSACryptoServiceProvider rSACryptoServiceProvider = new RSACryptoServiceProvider(parameters);
			byte[] rgb = Convert.FromBase64String(value);
			byte[] bytes = rSACryptoServiceProvider.Decrypt(rgb, fOAEP: false);
			return Encoding.GetEncoding(GetEncodeTypeActual.GetValue(codeType)).GetString(bytes);
		}
	}
}
